package com.bupt.liutong.admin.core.bo;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.transaction.annotation.Transactional;

import com.bupt.liutong.admin.core.base.BaseBo;
import com.bupt.liutong.admin.core.dao.ModuleDao;
import com.bupt.liutong.admin.core.dto.Module;
import com.bupt.liutong.admin.core.form.ModuleForm;
import com.bupt.liutong.util.BeanUtils;

public class ModuleBo extends BaseBo {

	private ModuleDao moduleDao;
	
	public List<ModuleForm> getModulesByPage(ModuleForm moduleForm, HttpServletRequest request) {
		Module module = new Module();
		sm.pagingWithNoCriteria(moduleForm, module, "core_module.getModulesCount");
		List<Module> moduleList = moduleDao.getModulesByPage(module);
		List<ModuleForm> moduleFormList = BeanUtils.dtoToForm(moduleList,
				ModuleForm.class);
		return moduleFormList;
	}
	
	/*
	public ModuleForm getModuleBy?(ModuleForm moduleForm)
			throws IllegalAccessException, InvocationTargetException,
			NoSuchMethodException {
		ModuleForm resultForm = new ModuleForm();
		BeanUtils.copyProperties(resultForm, moduleDao.getModuleById(moduleForm.get?()));
		return resultForm;
	}
	*/
	
	@Transactional
	public void insertModule(ModuleForm moduleForm) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		Module module = new Module();
		BeanUtils.copyProperties(module, moduleForm);
		moduleDao.insertModule(module);
	}

	@Transactional
	public int updateModule(ModuleForm moduleForm) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		Module module = new Module();
		BeanUtils.copyProperties(module, moduleForm);
		return moduleDao.updateModule(module);
	}
	
	/*
	private int deleteModuleById(? id){
		return moduleDao.deleteModuleById(id);
	}
	*/
	
	/*
	public int deleteModuleListById(String[] ids) {
		int row = 0;
		for (int i = 0; i < ids.length; i++) {
			row += deleteModuleById(Integer.parseInt(ids[i]));
		}
		return row;
	}
	*/

	public void setModuleDao(ModuleDao moduleDao) {
		this.moduleDao = moduleDao;
	}
}

